package com.ljh.order.service;

import com.ljh.order.mapper.OrderInfoMapper;
import com.ljh.order.model.OrderInfo;
import com.ljh.order.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author: Themberfue
 * @date: 2025/4/10 19:10
 * @description:
 */
@Service
public class OrderService {
    @Autowired
    OrderInfoMapper orderInfoMapper;

    @Autowired
    RestTemplate restTemplate;

    public OrderInfo getOrderById(Integer orderId) {
        OrderInfo orderInfo = orderInfoMapper.selectOrderById(orderId);

        // TODO 1. 构造请求 url
        String url = "http://product-service/product/" + orderInfo.getProductId();
        // TODO 2. 发送请求
        ProductInfo productInfo = restTemplate.getForObject(url, ProductInfo.class);

        orderInfo.setProductInfo(productInfo);
        return orderInfo;
    }
}
